window.onload=function(){
    let btn=document.querySelector("button")
    let btn_post=document.querySelector("#btn_post")
    btn.addEventListener("click",(e)=>{
        e.preventDefault()
        let username = document.getElementById("username").value
        let password = document.getElementById("password").value 
        fetch("http://172.19.1.251:8080/login",{
            method:"GET",
            headers:{
                "Content-Type":"application/x-www"
            }
        }).then((res)=>{
            console.log("get请求成功")
            console.log(res)
        }).catch(()=>{
            console.log("get请求失败")
        })
    })
    
    btn_post.addEventListener("click",(e)=>{
        e.preventDefault()
        let username = document.getElementById("username").value
        let password = document.getElementById("password").value 
        let data={
            username:username,
            password:password
        }
        let dataJson=JSON.stringify(data)
        console.log(dataJson)
        fetch("http://172.19.1.251:8080/login",{
            method:"POST",
            headers:{
                "Content-Type":"application/json"
            },
            body:dataJson
        }).then(()=>{
            console.log("post请求成功")
        }).catch(()=>{
            console.log("post请求失败")
        })
    })
}